#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    bool canJump(vector<int>& nums) {
        int left = 0, right = 0, mpos = 0;
        while (left <= right)
        {
            if (right >= nums.size() - 1) return true;
            for (int i = left; i <= right; i++)
                mpos = max(mpos, i + nums[i]);
            left = right + 1;
            right = mpos;
        }
        return false;
    }
};